package com.shaoshaohuo.app.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.NewPickEntity;
import com.squareup.picasso.Picasso;

import java.io.Serializable;
import java.util.List;

/**
 * Created by Administrator on 2017/6/9.
 */

public class PicDetailsFragmentBottom extends Fragment {

    private NewPickEntity bottom;

    public static PicDetailsFragmentBottom newInstance(Serializable s) {

        Bundle args = new Bundle();
        args.putSerializable("bottom", s);
        PicDetailsFragmentBottom fragment = new PicDetailsFragmentBottom();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_picdetails_bottmlayhout, null);

        return inflate;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        LinearLayout fragment_detalis_bottom_lin = (LinearLayout) view.findViewById(R.id.fragment_detalis_bottom_lin);
        Bundle arguments = getArguments();
        bottom = (NewPickEntity) arguments.getSerializable("bottom");
        init(view);
    }

    private void init(View view) {

        TextView gm_phone = (TextView) view.findViewById(R.id.gm_phone);
        String phone = bottom.getData().getPhone();
        gm_phone.setText(phone);
        TextView gm_youxiaoqi = (TextView) view.findViewById(R.id.gm_youxiaoqi);
        gm_youxiaoqi.setText(bottom.getData().getOpenTimeSta() + "至" + bottom.getData().getOpenTimeEnd() + "（周末法定节假日通用）");
        LinearLayout gm_imalist = (LinearLayout) view.findViewById(R.id.gm_imalist);
        List<NewPickEntity.DataBean.ImgDetailsBean> img_details = bottom.getData().getImg_details();
        for (int i = 0; i < img_details.size(); i++) {
            ImageView imageView = new ImageView(getContext());
            gm_imalist.addView(imageView);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
            layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
            layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
            Picasso.with(getContext()).load(img_details.get(i).getImg()).into(imageView);
        }
    }
}
